package com.gzsxy.esjy.service.netty.decoder;

import java.util.HashSet;
import java.util.Set;

/**
 * 文件路径解析
 * @author zhangxiaolong
 * @date 2022/7/11 9:36
 */
public class FilePathParser {

	/**
	 * 系统id
	 */
	private String systemId;

	/**
	 * 访问索引
	 */
	private String directIndex;

	/**
	 * 原图索引
	 */
	private String oriDirectIndex;

	private String param1 ;
	
	private String param2;
	
	public void createDirectIndex(){
		if(param1 == null) {
			this.directIndex = this.oriDirectIndex ;
		}else {
			int lastIndex = this.oriDirectIndex.lastIndexOf(".");
			String pre =this.oriDirectIndex ;
			if(lastIndex > 0) {
				this.type = this.oriDirectIndex.substring(lastIndex+1) ;
				pre = this.oriDirectIndex.substring(0,lastIndex) ;
			}
			pre = pre +"_"+param1;
			if(param2 != null) {
				pre = pre +"x"+param2;
			}
			this.directIndex = pre +"."+type ;
		}
	}
	


	public String getParam1() {
		return param1;
	}

	public void setParam1(String param1) {
		this.param1 = param1;
	}

	public String getParam2() {
		return param2;
	}

	public void setParam2(String param2) {
		this.param2 = param2;
	}



	/**
	 * 文件类型
	 */
	private String type = "";

	public String getSystemId() {
		return systemId;
	}

	public String getDirectIndex() {
		return directIndex;
	}

	

	public void setSystemId(String systemId) {
		this.systemId = systemId;
	}

	public void setDirectIndex(String directIndex) {
		this.directIndex = directIndex;
	}


	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getOriDirectIndex() {
		return oriDirectIndex;
	}

	public void setOriDirectIndex(String oriDirectIndex) {
		this.oriDirectIndex = oriDirectIndex;
	}
	
	
	private static Set<String> PIC_TYPE = new HashSet<>() ;
	
	static {
		PIC_TYPE.add("jpg");
		PIC_TYPE.add("jpeg");
		PIC_TYPE.add("png");
	}

	public boolean change() {
		return PIC_TYPE.contains(type) && param1 != null;
	}
}